package com.htjc.integral.account.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.htjc.integral.account.annotation.InvokeLog;
import com.htjc.integral.account.annotation.Signature;
import com.htjc.integral.account.service.INewAccountService;
import com.htjc.integral.account.util.ResultModel;

import lombok.extern.slf4j.Slf4j;

/**
 * 新账户体系  controller层
 * 
 *
 * @author hlc
 */
@Slf4j(topic = "jfLog")
@RestController
@RequestMapping(value = "/ac/sign")
public class NewAccountSignController {

	@Autowired
	INewAccountService accountServiceImpl;

	/**
	 * 积分划转(暂不支持浙江山东福建湖北)
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名积分划转",params={"ACCOUNT_NAME","BUSINESS_ID","ACCOUNT_ID","CHANNEL_NO"
			,"POWER_USER_LIST","SIGN","DEAL_TIME","ACCT_DATE"})
	@Signature(verifyFields={"ACCOUNT_NAME","ACCOUNT_ID","BUSINESS_ID","POWER_USER_LIST"})
	@RequestMapping(value = {"/changeIntegral"}, produces = {"text/json;charset=UTF-8;", "application/json;"})
	public String changeIntegral(@RequestBody String params){
		JSONObject resultJson=new JSONObject();
		try {
			//01：积分划转 02：缴费积分划转
			resultJson= accountServiceImpl.changeIntegral(JSON.parseObject(params),"01");
		} catch (Exception e) {
			log.error("【签名积分划转】异常",e);
			return ResultModel.ReturnErrorJson().toString();
		}
		return resultJson.toString();
	}

	/**
	 * 缴费积分划转(暂不支持浙江山东福建湖北)
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名缴费积分划转",params={"ACCOUNT_NAME","BUSINESS_ID","ACCOUNT_ID","CHANNEL_NO"
			,"POWER_USER_LIST","SIGN","DEAL_TIME","ACCT_DATE"})
	@Signature(verifyFields={"ACCOUNT_NAME","ACCOUNT_ID","BUSINESS_ID","DEDUCTION_NUM","POWER_USER_LIST"})
	@RequestMapping(value = {"/payChangeIntegral"}, produces = {"text/json;charset=UTF-8;", "application/json;"})
	public String payChangeIntegral(@RequestBody String params){
		JSONObject resultJson=new JSONObject();
		try {
			//01：积分划转 02：缴费积分划转
			resultJson=accountServiceImpl.changeIntegral(JSON.parseObject(params),"02");
		} catch (Exception e) {
			log.error("【签名缴费积分划转】异常",e);
			return ResultModel.ReturnErrorJson().toString();
		}
		return resultJson.toString();
	}

	/**
	 * 积分余额查询
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名积分余额查询",params={"ACCOUNT_ID","CHANNEL_NO","ACCOUNT_NAME","SIGN"})
	@Signature(verifyFields={"ACCOUNT_NAME","ACCOUNT_ID","BUSINESS_ID"})
	@RequestMapping(value = {"/queryIntegral"}, produces = {"text/json;charset=UTF-8;", "application/json;"})
	public String queryIntegral(@RequestBody String params){
		JSONObject resultJson=new JSONObject();
		try {
			resultJson= accountServiceImpl.queryIntegral(JSON.parseObject(params));
		} catch (Exception e) {
			log.error("【签名积分余额查询】异常",e);
			return ResultModel.ReturnErrorJson().toString();
		}
		return resultJson.toString();
	}

	/**
	 * 积分明细查询
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名积分明细查询",params={"ACCOUNT_ID","CHANNEL_NO","PAGE_INDEX","SIGN"})
	@Signature(verifyFields={"ACCOUNT_ID","BUSINESS_ID"})
	@RequestMapping(value = {"/queryIntegralDetail"}, produces = {"text/json;charset=UTF-8;", "application/json;"})
	public String queryIntegralDetail(@RequestBody String params) {
		return accountServiceImpl.queryIntegralDetail(JSON.parseObject(params)).toString();
	}

	/**
	 * 积分余额增加
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名积分余额增加",params={"ACCOUNT_ID","CHANNEL_NO","ACCOUNT_NAME","BUSINESS_ID"
			,"BUSS_TYPE","OPERATION_TYPE","BUSS_DISCRIBLE","INTEGRAL","DEAL_TIME","CREATE_DATE","ACCT_DATE","SIGN"})
	@Signature(verifyFields={"ACCOUNT_NAME","ACCOUNT_ID","BUSINESS_ID","INTEGRAL"})
	@RequestMapping(value = {"/addIntegral"}, produces = {"text/json;charset=UTF-8;", "application/json;"})
	public String addIntegral(@RequestBody String params){
		JSONObject resultJson=new JSONObject();
		try {
			resultJson= accountServiceImpl.addIntegral(JSON.parseObject(params));
		} catch (Exception e) {
			log.error("【签名积分余额增加】异常",e);
			return ResultModel.ReturnErrorJson().toString();
		}
		return resultJson.toString();
	}

	/**
	 * 积分余额扣减
	 * @param params
	 * @return
	 */
	@InvokeLog(value="签名积分余额扣减",params={"ACCOUNT_ID","CHANNEL_NO","ACCOUNT_NAME","OPERATION_TYPE"
			,"BUSS_TYPE","BUSS_DISCRIBLE","BUSINESS_ID","INTEGRAL","DEAL_TIME","ACCT_DATE","SIGN"})
	@Signature(verifyFields={"ACCOUNT_NAME","ACCOUNT_ID","BUSINESS_ID","INTEGRAL"})
	@RequestMapping(value = {"/deductionIntegral"}, produces = {"application/json;"})
	public String deductionIntegral(@RequestBody String params){
		JSONObject resultJson=new JSONObject();
		try {
			resultJson= accountServiceImpl.deductionIntegral(JSON.parseObject(params),true);
		} catch (Exception e) {
			log.error("【签名积分余额扣减】异常",e);
			return ResultModel.ReturnErrorJson().toString();
		}
		return resultJson.toString();
	}


}
